<?php

	echo "<script language='javascript'>

	function mostrarAba(id) {
		abaVisivel = document.getElementById('AssistidoAbaVisivel').value;
		document.getElementById('aba'+abaVisivel).style.display = 'none';

		document.getElementById('AssistidoAbaVisivel').value = id;
		document.getElementById('aba'+id).style.display = '';

		/* Modifica a cor da aba */
		document.getElementById('atab'+abaVisivel).className = 'tabBegin';
		document.getElementById('litab'+abaVisivel).className = 'tabEnd';

		document.getElementById('atab'+id).className = 'tabBeginSelected';
		document.getElementById('litab'+id).className = 'tabEndSelected';
	}

	</script>";
		echo $html->css('fd-datepicker');
	echo $javascript->link('datepicker.js');
	echo $accessibility->whereIAm($pageTitle);
	echo "<h2 id='contentTitle'>".$pageTitle."</h2>";

	echo $this->renderElement('message');

	/* Aba - Begin */
	echo "<div id='tab' class='tab'>";
	echo "<ul>";
	echo "<li id='litab0' class='tabEndSelected' style='padding-bottom: 6px;'>";
	echo "<a id='atab0' class='tabBeginSelected' href='javascript:mostrarAba(0); '>".
		 "<span  id='spantab0'>Dados</span></a>";
	echo "</li>";
	$k = 1;
	foreach ($formularios as $formulario) {
		echo "<li id='litab".$k."' class='tabEnd' style='padding-bottom: 6px;'>";
		$span = "<span id='spantab".$k."' >";
		echo "<a id='atab".$k."' class='tabBegin' href='javascript:mostrarAba(".$k.");'>".
			 $span.$formulario['Formulario']['name']."</span></a>\n";
		echo "</li>";
		$k++;
	}
	echo "</ul>";
	echo "</div>";
	/* Aba - End */

	echo $form->create(null,array('type' => 'file'));
	echo "<div id='aba0'>";
	echo $form->hidden('abaVisivel', array('value'=>0));
	echo $form->input('nome',array('label'=>$accessibility->required('Nome')));
	echo $form->input('endereco',array('label'=>'Endereço'));
	echo $form->input('bairro',array('label'=>'Bairro'));
	echo $form->input('rg',array('label'=>'RG'));
	echo $form->input('cpf',array('label'=>'CPF'));
	//echo $form->input('birthdate',array('label'=>'Nascimento'));
	echo $form->label('Assistido.birthdate','Nascimento');
	echo $input->date('Assistido','birthdate',null);
	
	echo $form->label('unidade_id',$accessibility->required('Unidade'));
	echo $form->select('unit_id', $units, null, array())."<br/>";
	echo $input->city('add', 'Assistido', $estados);
	// Upload da imagem do usuário
	echo "<div class='input'>";
	echo $form->label('photo','Foto');
	echo $form->file('photo')."<br/>";
	echo "</div>";
	echo "</div>";

	$iFvalor = 0;
	$iFvalorText = 0;
	$iFvalorFile = 0;
	$j = 1;

	foreach ($formularios as $formulario) {
		echo "<div id='aba".$j."' style='display:none;'>";
		echo "<h3>".$formulario['Formulario']['name']."</h3>";
		foreach ($formulario["Fcampo"] as $campo) {
			switch ($campo["type"]) {
				case 'string':
					echo $form->hidden('Fvalor_'.$iFvalor.'.fcampo_id', array("value"=>$campo["id"]));
					echo $form->input('Fvalor_'.$iFvalor.'.string',array('label'=>$campo["name"]));
					$iFvalor++;
					break;
				case 'inteiro':
					echo $form->hidden('Fvalor_'.$iFvalor.'.fcampo_id', array("value"=>$campo["id"]));
					echo $form->input('Fvalor_'.$iFvalor.'.inteiro',array('label'=>$campo["name"]));
					$iFvalor++;
					break;
				case 'data':
					echo $form->hidden('Fvalor_'.$iFvalor.'.fcampo_id', array("value"=>$campo["id"]));
					echo $form->input('Fvalor_'.$iFvalor.'.data',array('label'=>$campo["name"]));
					$iFvalor++;
					break;
				case 'texto':
					echo $form->hidden('FvalorText_'.$iFvalorText.'.fcampo_id', array("value"=>$campo["id"]));
					echo $form->label('FvalorText_'.$iFvalorText.'.texto',$campo["name"]);
					echo $form->textarea('FvalorText_'.$iFvalorText.'.texto');
					$iFvalorText++;
					break;
				case 'file':
					echo $form->hidden('FvalorFile_'.$iFvalorFile.'.fcampo_id', array("value"=>$campo["id"]));
					echo $form->label('FvalorFile_'.$iFvalorFile.'.file',$campo["name"]);
					echo $form->file('FvalorFile_'.$iFvalorFile.'.file')."<br/>";
					$iFvalorFile++;
					break;
			}
		}
		$j++;
		echo "</div>";
	}
	echo "<br/>";
	echo $form->end('Cadastrar assistido');
